package cn.springboot.mybatis.dao.controller;

import cn.springboot.mybatis.dao.model.User;
import cn.springboot.mybatis.dao.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * controller
 *
 * @author junrui.wang
 * @create 2017/9/8
 */
@Controller
@ResponseBody
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
    public ModelAndView getUser(@PathVariable("id") String id){
        User user = userService.select(id);
        ModelMap model = new ModelMap();
        model.addAttribute("user", user);
        return new ModelAndView("user", model);
    }
}
